class tt {
  constructor(param) {
    this.name = param.name;
    this.id = param.id;
    this.callback = param.callback;
  }

  render() {
    if ($('.tt').length > 0) {
      $('.tt').html(
        `<div id=${this.id} >
              <p>这是新构造的一个元素</p>
              <button>click me</button>
          </div>`
      );
    }
    if ($(`#${this.id} button`)) {
      // this.callback.bind(this, $('#tt1'))
      // 这种写法是为个回调函数进行传参
      $(`#${this.id} button`).on('click', this.callback.bind(this, $('#tt1')));
    }
  }
}

let tt1 = new tt({
  id: 'tt1',
  name: 'dean',
  callback: function(dom) {
    // debugger
    dom.find('p').html('文字被改变了');
  }
});

tt1.render();

